package com.cqhfan.userservice.controller;

import com.cqhfan.core.domain.dto.PageDTO;
import com.cqhfan.core.domain.query.PageQuery;
import com.cqhfan.pojo.user.vo.UserFriendVO;
import com.cqhfan.pojo.user.vo.UserProfileVO;
import com.cqhfan.userservice.service.UserService;
import com.cqhfan.pojo.user.po.User;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 眭传洪
 * @create 2025-07-21 22:03
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @GetMapping("/getByUserName/{userName}")
    public User getByUserName(@PathVariable("userName") String userName) {
        return userService.getByUserName(userName);
    }

    @GetMapping("/getByPhone/{phone}")
    public User getByUserPhone(@PathVariable("phone") String phone) {
        return userService.getByUserPhone(phone);
    }

    @GetMapping("/listByIds")
    public List<User> listByIds(@RequestParam("userIds") List<Long> userIds) {
        return userService.listByIds(userIds);
    }

    /**
     * “我的”页面信息查询，如果userId未传递代表查询的其他的用户信息
     */
    @GetMapping("/profile")
    public UserProfileVO profile(@RequestParam(value = "userId", required = false) Long userId) {
        return userService.profile(userId);
    }

    @PostMapping("/save")
    public Long save(@RequestBody User user) {
        return userService.saveUser(user);
    }

    @PutMapping("/updateUserInfo")
    public void updateUserInfo(@RequestBody User user) {
        userService.updateUserInfo(user);
    }

    @GetMapping("/pageFriend")
    public PageDTO<UserFriendVO> pageFriend(PageQuery query) {
        return userService.pageFriend(query);
    }

}
